import requests
import json
import sys
import requests
import json

# print("传递的参数:", sys.argv)  # 调试打印
# if len(sys.argv) > 1:
#     JOB_URL = sys.argv[1]
#     print("JOB_URL 是:", JOB_URL)  # 调试打印
# else:
#     print("错误: 缺少 JOB_URL 参数。")
#     sys.exit(1)

JOB_URL = r"http://192.168.40.129:9001/job/jenkins_pytest_allure/allure/"

def send_message():
    url = 'https://open.feishu.cn/open-apis/bot/v2/hook/d9f549c3-ec62-408b-b5fd-5a7789e1af66'  # 替换为你的 Webhook URL
    headers = {
        'Content-Type': 'application/json',
        'charset': 'utf-8'
    }
    data = {
        "msg_type": "interactive",
        "card": {
            "config": {
                "wide_screen_mode": True,
                "enable_forward": True
            },
            "elements": [{
                "tag": "div",
                "text": {
                    "content": "接口自动化测试完成，可以继续后续验证。",
                    "tag": "lark_md"
                }
            },
                {
                "actions": [{
                    "tag": "button",
                    "text": {
                        "content": "查看测试报告",
                        "tag": "lark_md"
                    },
                    "url": JOB_URL,
                    "type": "default",
                    "value": {}
                }
                ],
                "tag": "action"
            }
            ],
            "header": {
                "title": {
                    "content": "接口巡检",
                    "tag": "plain_text"
                }
            }
        }
    }



    # 发送 POST 请求
    response = requests.request(method="post",url=url, data=json.dumps(data), headers=headers)
    # print("飞书 API 响应:", response.status_code, response.text)
    # 返回响应内容
    return response.json()

if __name__== '__main__':
    send_message()
# 调用函数发送消息


#curl.exe -X POST -H "Content-Type: application/json" -d '{\"msg_type\":\"text\",\"content\":{\"text\":\"requestexample\"}}' https://open.feishu.cn/open-apis/bot/v2/hook/****